// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import Vconsole from 'vconsole';
// import Vuex from 'vuex'
import '../../lib/common.js';
import store from '@/store/index.js';
import handAccountCanvas from '@/assets/utils/core';
Vue.prototype.handAccountCanvas = handAccountCanvas;
import {
  Toast,
  Popup,
  Tab,
  Tabs,
  Image as VanImage,
  Col,
  Row,
  Lazyload,
  Field,
  Slider,
  Uploader,
  Button,
  NoticeBar,
  Icon,
  Dialog,
  RadioGroup,
  Radio,
  Search,
  IndexBar,
  IndexAnchor,
  Grid,
  GridItem,
  Empty,
  Collapse,
  CollapseItem
} from 'vant';
Vue.use(Toast);
Vue.use(Popup);
Vue.use(Tab);
Vue.use(Tabs); 
Vue.use(VanImage);
Vue.use(Col);
Vue.use(Row);
Vue.use(Lazyload);
Vue.use(Field);
Vue.use(Slider);
Vue.use(Uploader);
Vue.use(Button);
Vue.use(NoticeBar);
Vue.use(Icon);
Vue.use(Dialog);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Search);
Vue.use(IndexBar);
Vue.use(IndexAnchor);
Vue.use(Grid);
Vue.use(GridItem);
Vue.use(Empty);
Vue.use(Collapse);
Vue.use(CollapseItem);

if (process.env.NODE_ENV !== 'production') {
  Vue.prototype.$vConsole = new Vconsole()
}

// 获取链接头参数
function queryURLParams() {
  let url = location.search; // 项目中可直接通过search方法获取url中"?"符后的字串
  url = url.split("?")[1];
  let obj = {}; // 声明参数对象
  if (url) {
    url = UrlDecode(url);
    let arr = url.split("&"); // 以&符号分割为数组
    for (let i = 0; i < arr.length; i++) {
      let arrNew = arr[i].split("="); // 以"="分割为数组
      obj[arrNew[0]] = arrNew[1];
    }
  }
  return obj;
};

// 链接参数decode
function UrlDecode(zipStr) {
  var uzipStr = "";
  for (var i = 0; i < zipStr.length; i++) {
    var chr = zipStr.charAt(i);
    if (chr == "+") {
      uzipStr += " ";
    } else if (chr == "%") {
      var asc = zipStr.substring(i + 1, i + 3);
      if (parseInt("0x" + asc) > 0x7f) {
        uzipStr += decodeURI("%" + asc.toString() + zipStr.substring(i + 3, i + 9).toString());
        i += 8;
      } else {
        uzipStr += AsciiToString(parseInt("0x" + asc));
        i += 2;
      }
    } else {
      uzipStr += chr;
    }
  }
  return uzipStr;
}

let queryParams = queryURLParams();
store.dispatch('user/setBusinessId', queryParams.business_id);
store.dispatch('user/setOrigin', queryParams.origin);
store.dispatch('user/setQueryParams', queryParams);
handAccountCanvas.getAliyunCosSignatureFn();

import Index from './page/Index.vue';
/* eslint-disable no-new */
new Vue({
  store,
  el: '#root',
  components: {
    Index
  },
  template: '<Index/>'
})
